package com.bjsxt.base.mytest;

/**
 * 内部类实现单例模式  好处：实现延迟加载，且是线程安全的，不用加锁，所以多线程环境下不会影响性能
 */
public class StaticSingleton {
    private StaticSingleton(){

    }
    private static class SingletonHolder{
        private static StaticSingleton staticSingleton = new StaticSingleton();
    }
    public static StaticSingleton getInstance(){
        return SingletonHolder.staticSingleton;
    }

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            System.out.println(StaticSingleton.getInstance());
        }
    }
}
